home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / tests / thrash / RCS / thrash.c,v < prev   
Encoding:
Text File  |  1992-07-17  |  6.4 KB  |  283 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  srv030:1.3 srv027:1.3 srv026:1.3 srv024:1.3 srv021:1.3 srv018:1.3 srv014:1.3 srv010:1.3 srv008:1.3 srv007:1.3 srv006:1.3 srv004:1.3;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     92.01.22.13.22.14;  author kupfer;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     91.11.14.20.31.30;  author kupfer;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     91.11.09.22.08.21;  author kupfer;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @Program to cause lots of VM activity.
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @Add compile-time constants for name of file, number of iterations.
  33. Fix a bug in computing the status per cent.  Give a better error
  34. message if the file contains bad data.
  35. @
  36. text
  37. @/* 
  38.  * thrash.c --
  39.  *
  40.  *    Test program to cause lots of paging.
  41.  *
  42.  * Copyright 1991 Regents of the University of California
  43.  * Permission to use, copy, modify, and distribute this
  44.  * software and its documentation for any purpose and without
  45.  * fee is hereby granted, provided that this copyright
  46.  * notice appears in all copies.  The University of California
  47.  * makes no representations about the suitability of this
  48.  * software for any purpose.  It is provided "as is" without
  49.  * express or implied warranty.
  50.  */
  51.  
  52. #ifndef lint
  53. static char rcsid[] = "$Header: /r3/kupfer/spriteserver/tests/thrash/RCS/thrash.c,v 1.2 91/11/14 20:31:30 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
  54. #endif /* not lint */
  55.  
  56. #include <mach.h>
  57. #include <ctype.h>
  58. #include <status.h>
  59. #include <stdio.h>
  60. #include <stdlib.h>
  61. #include <sys/types.h>
  62. #include <test.h>
  63. #include <vm.h>
  64.  
  65. /* 
  66.  * Name of the big mapped file to create.
  67.  */
  68. #define FILE_NAME    "DummyFile"
  69.  
  70. /* 
  71.  * Number of iterations to walk through the file.
  72.  */
  73. #define ITERATIONS    3
  74.  
  75. Boolean gentle = FALSE;        /* pause between faults? */
  76.  
  77. /* Forward references */
  78.  
  79. static void MakeFile _ARGS_((char *fileName));
  80.  
  81. main(argc, argv)
  82.     int argc;
  83.     char *argv[];
  84. {
  85.     int bufferLength = 32 * 1024 * 1024;
  86.     char *buffer;
  87.     int iter;            /* iteration count */
  88.     char *cp;
  89.     ReturnStatus status;
  90.  
  91.     if (argc > 1) {
  92.     gentle = TRUE;
  93.     }
  94.  
  95.     status = Vm_MapFile(FILE_NAME, FALSE, (off_t)0,
  96.             (vm_size_t)bufferLength, &buffer);
  97.     if (status != SUCCESS) {
  98.     Test_PutMessage("Couldn't map file: ");
  99.     Test_PutMessage(Stat_GetMsg(status));
  100.     Test_PutMessage("\n");
  101.     goto bailOut;
  102.     }
  103.  
  104.     /* 
  105.      * Touch all the pages in the file, then wait a bit before 
  106.      * repeating.  Verify that the value you wrote is still there.  
  107.      * Pause before touching each page so as to reduce the load on 
  108.      * Mach.  (Running at full speed eventually causes the ethernet 
  109.      * interface to get a bus error, at least on a sun3.)
  110.      */
  111.     for (iter = 0; iter < ITERATIONS; iter++) {
  112.     Test_PutMessage("iteration ");
  113.     Test_PutDecimal(iter+1);
  114.     Test_PutMessage(": ");
  115.     for (cp = buffer; cp < buffer + bufferLength;
  116.          cp += vm_page_size) {
  117.         if (gentle) {
  118.         msleep(250);
  119.         }
  120.         if ((cp - buffer) % (20 * vm_page_size) == 0) {
  121.         Test_PutDecimal(100 * (unsigned)(cp - buffer) / bufferLength);
  122.         Test_PutMessage(" ");
  123.         }
  124.         if (iter > 0) {
  125.         if (*cp != 'a' + iter - 1) {
  126.             Test_PutMessage("thrash: wrong value (");
  127.             Test_PutHex(*(unsigned char *)cp);
  128.             Test_PutMessage(") at offset ");
  129.             Test_PutHex(cp - buffer);
  130.             Test_PutMessage("\n");
  131.         }
  132.         }
  133.         *cp = 'a' + iter;
  134.     }
  135.  
  136.     Test_PutMessage("pausing\n");
  137.     msleep(1000);
  138.     }
  139.  
  140.  bailOut:
  141.     exit(0);
  142. }
  143. @
  144.  
  145.  
  146. 1.2
  147. log
  148. @Change to new setup for sprited clients ((almost) no knowledge of
  149. Mach, etc.).
  150. @
  151. text
  152. @d17 1
  153. a17 1
  154. static char rcsid[] = "$Header: /r3/kupfer/spriteserver/tests/thrash/RCS/thrash.c,v 1.1 91/11/09 22:08:21 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)";
  155. d24 2
  156. d29 10
  157. d49 1
  158. a49 1
  159.     int bufferLength = 16 * 1024 * 1024;
  160. d59 2
  161. a60 1
  162.     status = Vm_MapFile("DummyFile", FALSE, 0, bufferLength, &buffer);
  163. d75 1
  164. a75 1
  165.     for (iter = 0; iter < 5; iter++) {
  166. d85 1
  167. a85 1
  168.         Test_PutDecimal(100 * (cp - buffer) / bufferLength);
  169. d90 5
  170. a94 1
  171.             Test_PutMessage("value mismatch\n");
  172. @
  173.  
  174.  
  175. 1.1
  176. log
  177. @Initial revision
  178. @
  179. text
  180. @d17 1
  181. a17 1
  182. static char rcsid[] = "$Header: /user6/kupfer/spriteserver/src/client/RCS/client.c,v 1.6 91/08/30 16:06:00 kupfer Exp $ SPRITE (Berkeley)";
  183. d20 1
  184. a21 2
  185. #include <mach.h>
  186. #include <mach_error.h>
  187. d24 2
  188. a25 2
  189. #include <user/proc.h>
  190. #include "spriteSrv.h"
  191. d27 1
  192. a27 1
  193. mach_port_t serverPort;        /* port for making Sprite requests */
  194. a31 2
  195. static void MapFile _ARGS_((char *fileName, boolean_t readOnly,
  196.                 int length, Address *startAddrPtr));
  197. d33 3
  198. a35 1
  199. main()
  200. a36 1
  201.     kern_return_t kernStatus;
  202. d41 1
  203. d43 2
  204. a44 3
  205.     kernStatus = task_get_bootstrap_port(mach_task_self(), &serverPort);
  206.     if (kernStatus != KERN_SUCCESS) {
  207.     thread_suspend(mach_thread_self());    
  208. d47 5
  209. a51 2
  210.     MapFile("DummyFile", FALSE, bufferLength, &buffer);
  211.     if (buffer == 0) {
  212. d60 1
  213. a60 1
  214.      * interface to get a bus error.)
  215. d63 3
  216. a65 3
  217.     Test_PutMessage(serverPort, "iteration ");
  218.     Test_PutDecimal(serverPort, iter+1);
  219.     Test_PutMessage(serverPort, ": ");
  220. d68 3
  221. a70 1
  222.         msleep(250);
  223. d72 2
  224. a73 3
  225.         Test_PutDecimal(serverPort,
  226.                 100 * (cp - buffer) / bufferLength);
  227.         Test_PutMessage(serverPort, " ");
  228. d77 1
  229. a77 1
  230.             Test_PutMessage(serverPort, "value mismatch\n");
  231. d83 1
  232. a83 1
  233.     Test_PutMessage(serverPort, "pausing\n");
  234. d88 1
  235. a88 44
  236.     Sys_Shutdown(serverPort);
  237. }
  238.  
  239.  
  240. /*
  241.  *----------------------------------------------------------------------
  242.  *
  243.  * MapFile --
  244.  *
  245.  *    Map the named file into our address space.
  246.  *
  247.  * Results:
  248.  *    Fills in the starting location, which is set to 0 
  249.  *    if there was a problem.
  250.  *
  251.  * Side effects:
  252.  *    None.
  253.  *
  254.  *----------------------------------------------------------------------
  255.  */
  256.  
  257. static void
  258. MapFile(fileName, readOnly, length, startAddrPtr)
  259.     char *fileName;        /* name of file to map */
  260.     boolean_t readOnly;        /* map read-only or read-write? */
  261.     int length;            /* number of bytes to map */
  262.     Address *startAddrPtr;    /* OUT: where the file was mapped to */
  263. {
  264.     kern_return_t kernStatus;
  265.     ReturnStatus status;
  266.  
  267.     kernStatus = Vm_MapFileStub(serverPort, fileName, strlen(fileName)+1,
  268.                 readOnly, 0, length, &status, startAddrPtr);
  269.     if (kernStatus != KERN_SUCCESS) {
  270.     Test_PutMessage(serverPort, "Couldn't map file: ");
  271.     Test_PutMessage(serverPort, mach_error_string(kernStatus));
  272.     Test_PutMessage(serverPort, "\n");
  273.     *startAddrPtr = 0;
  274.     } else if (status != SUCCESS) {
  275.     Test_PutMessage(serverPort, "Couldn't map file: ");
  276.     Test_PutMessage(serverPort, Stat_GetMsg(status));
  277.     Test_PutMessage(serverPort, "\n");
  278.     *startAddrPtr = 0;
  279.     }
  280. a89 1
  281.  
  282. @
  283.